| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 1 | <html> | 
 | 2 | <head> | 
 | 3 |  <!--#include virtual="header.html" --> | 
 | 4 |  <title>Joe Gregorio | BitWorking | Projects | httplib2.py</title> | 
 | 5 | </head> | 
 | 6 | <body class='main' id="top" name="top" > | 
 | 7 |  <div class="body"> | 
 | 8 |  <!--#include virtual="titlebar.html" --> | 
 | 9 |  | 
 | 10 |  <div class="content"> | 
 | 11 |   | 
| jcgregorio | 4ce467a | 2006-03-22 14:48:43 +0000 | [diff] [blame] | 12 |  <div> | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 13 |  | 
 | 14 |  <h2>Httplib2</h2> | 
 | 15 |  <p>A comprehensive HTTP client library, <code>httplib2.py</code>  | 
 | 16 |  supports many features left out of other HTTP libraries. | 
 | 17 |  </p> | 
 | 18 |  <dl> | 
 | 19 |  <dt>HTTP and HTTPS</dt> | 
 | 20 |  <dd>HTTPS support is only available if the socket module was compiled with SSL support. | 
 | 21 |  </dd> | 
 | 22 |  | 
 | 23 |  <dt>Keep-Alive</dt> | 
 | 24 |  <dd>Supports HTTP 1.1 Keep-Alive, keeping the socket  | 
 | 25 |  open and performing multiple requests over the same connection | 
 | 26 |  if possible. | 
 | 27 |  </dd> | 
 | 28 |  | 
 | 29 |  <dt>Authentication</dt> | 
 | 30 |  <dd>The following three types of HTTP Authentication are supported.  | 
 | 31 |  These can be used over both HTTP and HTTPS. | 
 | 32 |  <ul> | 
 | 33 |  <li><a href="http://www.faqs.org/rfcs/rfc2617.html">Digest</a></li> | 
 | 34 |  <li><a href="http://www.faqs.org/rfcs/rfc2617.html">Basic</a></li> | 
 | 35 |  <li><a href="http://www.xml.com/pub/a/2003/12/17/dive.html">WSSE</a></li> | 
 | 36 |  </ul> | 
 | 37 |  </dd> | 
 | 38 |  | 
 | 39 |  <dt>Caching</dt> | 
 | 40 |  <dd>The module can optionally operate with a private | 
 | 41 |  cache that understands the Cache-Control: header and | 
 | 42 |  uses both the ETag and Last-Modified cache validators. | 
 | 43 |  </dd> | 
 | 44 |  | 
 | 45 |  <dt>All Methods</dt> | 
 | 46 |  <dd>The module can handle any HTTP request method, not just GET and POST.</dd> | 
 | 47 |  | 
 | 48 |  <dt>Redirects</dt> | 
 | 49 |  <dd>Automatically follows 3XX redirects on GETs.</dd> | 
 | 50 |  | 
 | 51 |  <dt>Compression</dt> | 
 | 52 |  <dd>Handles both 'compress' and 'gzip' types of compression.</dd> | 
 | 53 |  | 
 | 54 |  <dt>Lost update support</dt> | 
 | 55 |  <dd>Automatically adds back ETags into PUT requests to resources | 
 | 56 |  we have already cached. This implements Section 3.2 of  | 
 | 57 |  <a href="http://www.w3.org/1999/04/Editing/#Table">Detecting the Lost Update Problem Using Unreserved Checkout</a></dd> | 
 | 58 |  | 
 | 59 |  <dt>Unit Tested</dt> | 
 | 60 |  <dd>A large and growing set of unit tests.</dd> | 
 | 61 |  | 
 | 62 |  </dl> | 
 | 63 |  | 
| jcgregorio | 4ce467a | 2006-03-22 14:48:43 +0000 | [diff] [blame] | 64 | <h3>Usage</h3> | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 65 |  | 
 | 66 | <p>A simple retrieval:</p> | 
 | 67 |  | 
| jcgregorio | b7753b3 | 2006-02-15 19:04:08 +0000 | [diff] [blame] | 68 | <pre><code>import httplib2 | 
 | 69 | h = httplib2.Http(".cache") | 
 | 70 | resp, content = h.request("http://example.org/", "GET") | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 71 | </code></pre> | 
 | 72 |  | 
 | 73 | <p>The 'content' is the content retrieved from the URL. | 
 | 74 | The content is already decompressed or unzipped if necessary. | 
| jcgregorio | b7753b3 | 2006-02-15 19:04:08 +0000 | [diff] [blame] | 75 | The 'resp' contains all the response headers. | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 76 | </p> | 
 | 77 |  | 
 | 78 | <p>To PUT some content to a server that uses SSL | 
 | 79 | and Basic authentication:</p> | 
 | 80 |  | 
| jcgregorio | b7753b3 | 2006-02-15 19:04:08 +0000 | [diff] [blame] | 81 | <pre><code>import httplib2 | 
 | 82 | h = httplib2.Http(".cache") | 
| jcgregorio | e34942d | 2006-05-08 01:06:37 +0000 | [diff] [blame] | 83 | h.add_credentials('name', 'password') | 
| jcgregorio | b7753b3 | 2006-02-15 19:04:08 +0000 | [diff] [blame] | 84 | resp, content = h.request("https://example.org/chap/2",  | 
 | 85 |  "PUT", body="This is text",  | 
 | 86 |  headers={'content-type':'text/plain'} ) | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 87 | </code></pre> | 
 | 88 |  | 
 | 89 | <p>Use the Cache-Control: header to control | 
 | 90 |  how the caching operates.</p> | 
 | 91 |  | 
| jcgregorio | b7753b3 | 2006-02-15 19:04:08 +0000 | [diff] [blame] | 92 | <pre><code>import httplib2 | 
 | 93 | h = httplib2.Http(".cache") | 
 | 94 | resp, content = h.request("http://bitworking.org/") | 
 | 95 |  ... | 
 | 96 | resp, content = h.request("http://bitworking.org/",  | 
 | 97 |  headers={'cache-control':'no-cache'}) | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 98 | </code></pre> | 
 | 99 |  | 
 | 100 | <p>The first request will be cached and since this is a request to  | 
 | 101 | bitworking.org it will be set to be cached for two hours, because | 
 | 102 | that is how I have my server configured. | 
 | 103 | Any subsequent GET to that URI will return the value from the | 
 | 104 | on-disk cache and no request will be made to the server. | 
 | 105 | You can use the Cache-Control: header to change the caches behavior and | 
 | 106 | in this example the second request adds the Cache-Control: header with a value | 
 | 107 | of 'no-cache' which tells the library that the cached copy | 
 | 108 | must not be used when handling this request. | 
 | 109 | </p> | 
 | 110 |  | 
| jcgregorio | 4ce467a | 2006-03-22 14:48:43 +0000 | [diff] [blame] | 111 | <h3>Requirements</h3> | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 112 |  | 
| jcgregorio | 1eed40f | 2006-02-15 18:56:46 +0000 | [diff] [blame] | 113 | <p>Requires Python 2.3 or later. Does not require | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 114 | any libraries beyond what is found in the core library.</p> | 
 | 115 |  | 
| jcgregorio | 4ce467a | 2006-03-22 14:48:43 +0000 | [diff] [blame] | 116 | <h3>Download/Installation</h3> | 
| jcgregorio | 1eed40f | 2006-02-15 18:56:46 +0000 | [diff] [blame] | 117 |  | 
 | 118 | <p>The httplib2 module is shipped as a distutils package. To install | 
 | 119 | the library, first unpack the distribution archive, and issue the following | 
 | 120 | command:</p> | 
 | 121 |  | 
 | 122 | <pre><code>$ python setup.py install</code></pre> | 
 | 123 |  | 
 | 124 | <p><a href="dist">Download the distribution archives from here</a>. </p> | 
 | 125 |  | 
 | 126 | <p> <a href="test">The resources used in the unit test cases</a> | 
 | 127 |  are available also. More documentation on them will be forthcoming.</p> | 
 | 128 |  | 
| jcgregorio | ec11493 | 2006-03-03 16:23:26 +0000 | [diff] [blame] | 129 | <p>You can also get the sources directly from the SourceForge hosted | 
 | 130 |  subversion repository.</p> | 
 | 131 |  | 
| jcgregorio | 4ce467a | 2006-03-22 14:48:43 +0000 | [diff] [blame] | 132 | <pre>svn co https://svn.sourceforge.net/svnroot/httplib2/trunk httplib2</pre> | 
 | 133 |  | 
 | 134 |  | 
 | 135 | <h3>Feedback</h3> | 
 | 136 |  | 
 | 137 | <p>Bugs and enhancement requests are handled through  | 
 | 138 | <a href="http://sourceforge.net/projects/httplib2/">SourceForge</a>, and anything is up for discussion | 
 | 139 | on the <a href="http://sourceforge.net/mail/?group_id=161082">httplib2 mailing list</a>. | 
 | 140 | </p> | 
 | 141 |  | 
 | 142 | <h3>To Do</h3> | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 143 |  | 
 | 144 | <p>This module is not perfect and needs the following:</p> | 
 | 145 | <ul> | 
 | 146 |  <li>Support for Proxies</li> | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 147 |  <li>A pluggable store for the cache. Right now the store is just flat files in a directory.  | 
 | 148 |  I would like to have plugins that allow keeping the cache in Berkeley DB, Squid, MySQL, etc.</li> | 
 | 149 |  <li>More unit tests</li> | 
 | 150 | </ul> | 
 | 151 |  | 
| jcgregorio | 4ce467a | 2006-03-22 14:48:43 +0000 | [diff] [blame] | 152 | <h3>Project Goal</h3> | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 153 |  | 
 | 154 | <p>To become a worthy addition to the Pyhton core library.</p> | 
 | 155 |  | 
| jcgregorio | 4ce467a | 2006-03-22 14:48:43 +0000 | [diff] [blame] | 156 | <h3>Additional Information</h3> | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 157 |  | 
 | 158 | <p> | 
 | 159 |  <dl> | 
 | 160 |  <dt>Author</dt> | 
 | 161 |  <dd>Joe Gregorio</dd> | 
 | 162 |  | 
 | 163 |  <dt>License</dt> | 
 | 164 |  <dd>MIT</dd> | 
 | 165 |  | 
 | 166 |  <dt>Contributors</dt> | 
| jcgregorio | 22a9e16 | 2006-03-22 14:45:46 +0000 | [diff] [blame] | 167 |  | 
 | 168 |  <dd> | 
 | 169 |  Thomas Broyer (t.broyer@ltgt.net) | 
 | 170 |  </dd> | 
 | 171 |  <dd> | 
 | 172 |  (Your name here) | 
 | 173 |  </dd> | 
 | 174 |  </dl> | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 175 | </p> | 
 | 176 |   | 
| jcgregorio | 1eed40f | 2006-02-15 18:56:46 +0000 | [diff] [blame] | 177 |  <p style="font-size: small">This page last updated on: $LastChangedDate$.</p> | 
| jcgregorio | 2d66d4f | 2006-02-07 05:34:14 +0000 | [diff] [blame] | 178 |  | 
 | 179 |  </div> | 
 | 180 |  </div> | 
 | 181 |  <!--#include virtual="footer.html" --> | 
 | 182 |  </div> | 
 | 183 | </body> | 
 | 184 |  | 
 | 185 | </html> |